<?php
/**
 * 获取登录后的分类列表
 * 验证用户身份token
 * @author Edwin
 */

namespace V1\Controller;

use Common\Controller\ApiController;
use Think\Exception;

class CategoryListController extends ApiController
{
    /**
     * 根据请求方式调用不同的方法
     * get方式调用_get方法
     */
    public function rest()
    {
        switch ($this->_method) {
            case 'get': // get请求处理代码
                $this->_get();
                break;
        }
    }

    /**
     * 输出关注的圈子列表
     */
    private function _get()
    {
        $user_id = $this->userId;
        try {
            $data = D('SelectedCategory')->get_my_category_list($user_id);
            if (!$data) {
                $this->myApiPrint(C('STATUS')['230'], 201, []);
            } else {
                foreach ($data AS $k => $v) {
                    $data[$k]['id'] = $v['cat_id'];
                    $data[$k]['cat_img'] =  'Uploads/'.$v['cat_img'];
                }
                $this->myApiPrint(C('STATUS')['200'], 200, $data);
            }
        } catch (Exception $exception) {
            $this->myApiPrint(C('STATUS')['101'], 400, []);
        }
    }
}
